﻿@using TestOnlineProject.Models.Entities
@{
    ViewBag.Title = "Index";
}
@{
    if (!String.IsNullOrEmpty(ViewBag.Msg))
    {
    <script>        alert("@ViewBag.Msg")</script>
    }
}
@*<script src="../../Scripts/jQuery/jquery-1.7.1.js" type="text/javascript"></script>*@
<script>
    // Select created by
    $(document).ready(function () {
        var values = $(".created_by").val();
        if (values == "actualUser") {
            $(".actual_user").css("display", "block");
        }
        else {
            $(".actual_user").css("display", "none");
        }

        $(".created_by").change(function () {
            var values = $(this).val();
            if (values == "actualUser") {
                $(".actual_user").css("display", "block");
            }
            else {
                $(".actual_user").css("display", "none");
            }

            // Clear actual people.
            $("#actualUser").val("");
            $("#actual_user").val("");
        });

        // Clear section.
        $("#section_name").focus(function(){
            $(this).val('');
            $("#sectionId").val('0');
        }); 

    });

    // Autpcomplete user.
    $(function () {
        $("#actual_user").autocomplete({
            source: "@Url.Content("~/Question/AutocompleteUser")",
            minLength: 1,
            select: function (event, ui) {
                if (ui.item) {
                    $("#actual_user").val(ui.item.value);
                    $("#actualUser").val(ui.item.id);
                }
            }
        });
    });

    // Autpcomplete section.
    $(function () {
        $("#section_name").autocomplete({
            source: "@Url.Content("~/Question/AutocompleteSection")?subjectId=@ViewBag.Subject.SubjectId",
            minLength: 1,
            select: function (event, ui) {
                if (ui.item) {
                    $("#section_name").val(ui.item.value);
                    $("#sectionId").val(ui.item.id);
                }
            }
        });
    });

</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Subjects", "Index", "Subject")
    / @Html.ActionLink((ViewBag.Subject as Subject).Code, "Details", "Subject", new { id = (ViewBag.Subject as Subject).SubjectId }, null)
    /
    @{
        if (@ViewBag.Section != null)
        {
            @Html.ActionLink("Sections", "Index", "Section", new {subjectId = @ViewBag.Subject.SubjectId}, null)
            <span>/</span>
            <span style="word-wrap: break-word">@ViewBag.Section.Name</span>
            <input type="hidden" name="import" value="-1"/>
        }
        else
        {
            <span>Questions</span>
            <input type="hidden" name="import" value="-1"/>
        }
    }
</div>
<br />
<div class="main_nav">
@{
    if(@ViewBag.Section != null)
    {
        <span>
        <a href="@Url.Content("~/Section")?subjectId=@ViewBag.Subject.SubjectId">
            <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/>
        </a>
    </span>
    }
    else
    {
    <span>
        <a href="@Url.Content("~/Subject/Details")?id=@ViewBag.Subject.SubjectId">
            <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/>
        </a>
    </span>
    }
    }
    
    <span style="float: right">
        @if (HttpContext.Current.User.IsInRole("1"))
        {
            @Html.ActionLink("Participants", "Index", "Participant", new { subjectId = ViewBag.Subject.SubjectId }, new { }) <span>|</span>
        }
        @{
            if (@ViewBag.Section != null)
            {
                @Html.ActionLink("Questions", "Index", "Question", new { subjectId = ViewBag.Subject.SubjectId }, new { })
                <span>|</span>
            }
            else
            {
                @Html.ActionLink("Sections", "Index", "Section", new { subjectId = ViewBag.Subject.SubjectId }, new { })
                <span>|</span>
            }
        }
        @Html.ActionLink("Tests", "Index", "Test", new { subjectId = ViewBag.Subject.SubjectId }, new { })
        |
        @Html.ActionLink("Discussions", "Index", "Discussion", new { subjectId = ViewBag.Subject.SubjectId }, new { })
    </span>
</div>
<br />
<div class="search_content">
    @using (Ajax.BeginForm("Index", "Question", new AjaxOptions
    {
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "GET",
        UpdateTargetId = "unobtrusive",
    }, new
    {
        @class
       = "form-inline"
    }))
    {
        <input  type="hidden" name="subjectId" value="@ViewBag.Subject.SubjectId"/>
        <input  type="hidden" name="sectionId" value="@ViewBag.SectionId"/>
        <input type="hidden" name="actualUser" id="actualUser" />
        <span>@Html.DropDownList("createdBy", @ViewBag.CreatedByList as SelectList, "Creator", new { @class = "created_by" })</span>
        <span>@Html.DropDownList("questionTypeId", @ViewBag.QuestionTypeList as SelectList, "Type", new { @class = "question_type" })</span>
        <input type="text" name="keyWord" placeholder="Question's Title" />
        <button type="submit" class="btn" value="Search" style="width: 80px">Search</button>
        if (ViewBag.SectionId > 0)
        {
            @Html.ActionLink("Reload", "Index", "Question", new { subjectId = @ViewBag.Subject.SubjectId, sectionId = ViewBag.SectionId }, new { @class = "btn", style = "width:54px" })
        }
        else
        {
            @Html.ActionLink("Reload", "Index", "Question", new { subjectId = @ViewBag.Subject.SubjectId, sectionId = @ViewBag.SectionId }, new { @class = "btn", style = "width:54px" })
        }
        <br />
        <input id="actual_user" type="text" class="actual_user" style="display: none; margin-top: 5px" placeholder="Full Name or Username" />
    }
</div>
<br />
@{
    if (ViewBag.SectionId > 0)
    {
        <span>@Html.ActionLink("Section Details", "Details", "Section", new { id = ViewBag.SectionId }, new { @class = "btn" })</span>
        if (ViewBag.Section.UserId == int.Parse(HttpContext.Current.User.Identity.Name))
        {
            <span>@Html.ActionLink("Create Question", "Create", "Question", new { subjectId = @ViewBag.Subject.SubjectId, sectionId = ViewBag.Section.SectionId }, new { @class = "btn" })</span>
            <span>@Html.ActionLink("Import Questions", "Import", "Question", new { id = @ViewBag.Subject.SubjectId, sectionId = ViewBag.Section.SectionId }, new { @class = "btn" })</span>
        }
    }
    else
    {
        <span>@Html.ActionLink("Create Question", "Create", "Question", new { subjectId = @ViewBag.Subject.SubjectId }, new { @class = "btn" })</span>
        <span>@Html.ActionLink("Import Questions", "Import", "Question", new { id = @ViewBag.Subject.SubjectId }, new { @class = "btn" })</span>
    }
}
<br />
<br />
<input type="hidden" name="import" value="0"/>
<div id="unobtrusive">
    @Html.Partial("_List")
</div>